Skip to content

Preserve typed nested unions in SDK codegen - #2486

Closed
gokhanarkan wants to merge 6 commits into
mainfrom
gokhanarkan/expose-catalogue-search
Closed

Preserve typed nested unions in SDK codegen#2486
gokhanarkan wants to merge 6 commits into
mainfrom
gokhanarkan/expose-catalogue-search

Conversation

@gokhanarkan

@gokhanarkan gokhanarkan commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

  • derive discriminators and unknown-variant policy from resolved JSON Schema variants in shared codegen metadata
  • select the proven failure shape without method or type name checks: a closed discriminated result whose variant directly owns an array of another closed discriminated union
  • propagate that policy only through nested closed unions below the selected list elements
  • keep all unrelated generated RPC output byte-identical

Part of #2106.

Narrow generated scope

For the exact current schema, the structural selector matches only catalog.search and derives exactly this policy graph:

  • CatalogSearchResult
  • CatalogCandidate
  • CatalogCandidateSource

Generation conformance asserts both facts, so any future widening fails for explicit review instead of silently changing generated APIs.

Language mapping remains idiomatic and limited to that graph:

  • TypeScript projects the selected response through generated schema metadata
  • Go rejects unknown selected variants while retaining existing raw wrapper types for source compatibility
  • .NET rejects unknown selected variants and requires their discriminator fields
  • Python emits explicit CodeQL-safe failure paths for the selected loaders
  • Java promotes the selected nested unions instead of List<Object> / Object
  • Rust already models the variants safely; only conformance coverage changes

No generator source checks CatalogCandidate, Catalog*, or catalog.search. A synthetic non-catalogue result proves the same structural selection, TypeScript projection, and Java promotion.

Schema input

Exact Copilot CLI 1.0.83-5, resolved from the canonical published release package. Java's npm schema input is exact and both the Maven update profile and dependency workflow use --save-exact.

Conformance

Published catalogue result types exercise the selected graph across all six SDKs:

  • known outer and nested variants
  • refusal and failure variants
  • opaque candidate handles
  • unknown and missing outer discriminators
  • unknown and missing candidate/source discriminators
  • extra untrusted fields at result, candidate, and nested source levels

Validation

  • shared and Java generation drift: clean
  • focused six-language conformance: passed
  • Node format, lint, typecheck, build, and release package verification: passed
  • Python Ruff, changed-file ty, focused tests, and package build: passed
  • Go focused and package tests: passed
  • .NET focused conformance and package build: passed
  • Rust format, Clippy, package, and focused conformance: passed
  • Java full mvn verify: passed
  • independent final diff review: no actionable issues

The final diff is 33 files against current main. It contains no unrelated generated RPC output, session-event churn, E2E adaptations, downloader, materialisation policy, or planning/apply generated types or business logic.